package com.xinjian.jianba.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import com.xinjian.jianba.dto.UserTrackSiteNamesDto;
import com.xinjian.jianba.dto.UserTrackSiteNamesVo;
import com.xinjian.jianba.dto.UserTrackSitePersonsDto;
import com.xinjian.jianba.dto.UserTrackSitePersonsVo;
import com.xinjian.jianba.exception.ResponseCode;
import com.xinjian.jianba.service.UserTrackService;
import com.xinjian.jianba.service.ValidatorService;
import com.xinjian.jianba.utils.JsonUtil;
import com.xinjian.jianba.utils.LogBuilder;
import com.xinjian.jianba.utils.ModuleEnum;
@RestController
@RequestMapping(value="/api/v3/jianba/userTrack")
public class UserTrackController extends AbstractController{
	private static final Logger LOGGER = LoggerFactory.getLogger(UserTrackController.class);

	@Autowired
	private UserTrackService userTrackService;
	@Autowired
	private ValidatorService validatorService;
	@PostMapping("/siteNames")
	public String getSiteNamesByUserId(@RequestBody UserTrackSiteNamesDto userTrackSiteNamesDto){
		LOGGER.info(LogBuilder.build(ModuleEnum.Tracks, "获取足迹列表, userTrackSiteNamesDto={}"), JsonUtil.getJsonString(userTrackSiteNamesDto));
		try {
			validatorService.valid(userTrackSiteNamesDto);
		} catch (Exception e) {
			LOGGER.error("--------error--->>>>>", e);
			return this.responseClientJsonData(ResponseCode.BAD_REQUEST, e.getMessage());
		}
		List<UserTrackSiteNamesVo> list=userTrackService.getSiteNamesByUserId(userTrackSiteNamesDto);
		return this.responseClientJsonData(ResponseCode.SUCCESS,ResponseCode.SUCCESS_MSG ,list);
	}
	@PostMapping("/siteUsers")
	public String getSiteUsers(@RequestBody UserTrackSitePersonsDto userTrackSitePersonsDto){
		LOGGER.info(LogBuilder.build(ModuleEnum.Tracks, "获取足迹人员列表, userTrackSitePersonsDto={}"), JsonUtil.getJsonString(userTrackSitePersonsDto));
			try {
				validatorService.valid(userTrackSitePersonsDto);
			} catch (Exception e) {
				LOGGER.error("--------error--->>>>>", e);
				return this.responseClientJsonData(ResponseCode.BAD_REQUEST, e.getMessage());
			}
			List<UserTrackSitePersonsVo> list=userTrackService.selectSitePersonsBySiteId(userTrackSitePersonsDto);
			return this.responseClientJsonData(ResponseCode.SUCCESS,ResponseCode.SUCCESS_MSG ,list);
	}
}
